var ctx = ctx;
$(function(){
    loadDiv('turnOutPatientListDiv',ctx+'/doctor/medicalRecord/findWaitTurnOutPatientList');
});

function showTurnOutForm(patientId,patVisitId){
    $("#turnOutPatientListDiv").attr("class","col-lg-8");
    $("#turnOutForm").show('normal');
    return loadDiv('turnOutForm',ctx+'/doctor/medicalRecord/findInfoByTurnOutParam?patientId='+patientId+'&patVisitId='+patVisitId);
}

function closeTurnOutForm(){
    $("#turnOutPatientListDiv").attr("class","col-lg-12");
    $("#turnOutPatientListDiv").show('normal');
    $("#turnOutForm").attr("style","display: none");
}


function formTurnOutLoad(divId,formId,url,hrefUrl){
    if(flag){
        if ($('#' + formId).parsley().validate()) {
            flag = false;
            $("#" + formId + " input,#" + formId + " select").removeAttr("disabled");
            $.ajax({
                type: "POST",
                data: $("#" + formId).serialize(),
                url: url,
                dataType: "json",
                success: function (data) {
                    // alert(data.code);
                    if (data.code == "1" || data.code == 1) {
                        if (data.data != null && data.data != '') {
                            var datas = eval(data.data);
                            for (var i = 0; i < datas.length; i++) {
                                if (datas[i].results == "1") {
                                    toastr.info(datas[i].message);
                                }
                            }
                        }

                    } else if (data.code == 0 || data.code == '0') {
                        toastr.success('移出病人病历成功');
                        parent.layer.closeAll(); //关闭当前弹层
                        parent.$("#searchForm").submit();

                    } else {
                        flag = true;
                        toastr.error(data.data);
                    }
                },
                error: function (data) {
                    toastr.error('网络连接错误,请检查网络');
                    flag = true;
                }
            });
        }
    }
    return false;
}